<template>
  <div class="home-new">

    <home-panel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
      <template #right>
        <xtx-more path='/'></xtx-more>
      </template>

      <div style="position:relative;height:406px" ref="target">
        <transition name="fade">
          <!-- 面板内容 -->
      <ul class="goods-list" v-if="goods.length">
        <li v-for="item in goods" :key="item.id">
          <RouterLink :to="`/product/${item.id}`">
            <img :src="item.picture" alt="">
            <p class="name ellipsis">{{item.name}}</p>
            <p class="price">&yen;{{item.price}}</p>
          </RouterLink>
        </li>
      </ul>

        <home-skeleton v-else bg="#f0f9f4"></home-skeleton>
        </transition>
      </div>

    </home-panel>
  </div>
</template>

<script>
import HomePanel from '@/views/home/components/home-panel'
import HomeSkeleton from '@/views/home/components/home-skeleton'
import XtxMore from '@/components/library/xtx-more'
// import { ref } from 'vue'
import { findNew } from '@/api/home.js'
import { useLazyData } from '@/hooks/index.js'
export default {
  name: 'HomeNew',

  components: {
    HomePanel,
    XtxMore,
    HomeSkeleton
  },

  setup () {
    // const goods = ref([])

    // findNew().then(res => {
    //   goods.value = res.result
    // })

    // 懒加载
    const { target, result } = useLazyData(findNew)

    return { goods: result, target }
  }

}
</script>

<style lang="less" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
